package com.app.base.service.core.organization.controller;


import com.alibaba.fastjson.JSONObject;
import com.app.base.service.core.organization.entity.Organization;
import com.app.base.service.core.organization.service.OrganizationService;
import com.app.base.utlis.auth.JwtHelper;
import com.app.base.utlis.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author yuhag
 * @since 2022-05-08
 */
@RestController
@RequestMapping("/organization")
@Api(tags = "组织架构")
public class OrganizationController {

    @Resource
    private OrganizationService organizationService;

    @PostMapping("saveOrg")
    @ApiOperation("添加组织架构")
    public Result saveOrEditOrg(HttpServletRequest request, @RequestBody Organization organization){
        return organizationService.saveOrg(request,organization);
    }

    @GetMapping("chart")
    @ApiOperation("组织架构图")
    public Result organizationChart(HttpServletRequest request){
        String userId = JwtHelper.getMemberIdByJwtToken(request);
        return organizationService.organizationChart(userId);
    }

    @GetMapping("structure")
    @ApiOperation("组织结构")
    public Result structure(HttpServletRequest request){
        return organizationService.structure(request);
    }

    @PostMapping("editOrganization")
    @ApiOperation("更新组织架构")
    public Result editOrganization(HttpServletRequest request, @RequestBody JSONObject json){
        return organizationService.editOrganization(json,request);
    }

    @GetMapping("deptList")
    @ApiOperation("部门列表")
    public Result deptList(HttpServletRequest request){
        return organizationService.deptList(request);
    }


    @DeleteMapping("del/{grade}/{id}")
    @ApiOperation("删除组织架构")
    public Result deleteOrganization(@PathVariable(value = "grade") Integer grade,
                                     @PathVariable(value = "id")String id) {
        return organizationService.deleteOrganization(grade,id);
    }

    @GetMapping("sel/{grade}/{id}")
    public Result selEmp(@PathVariable(value = "grade") Integer grade,
                         @PathVariable(value = "id")String id) {
        return organizationService.selEmp(grade,id);
    }

}

